home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!taumet!clamage
- From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
- Newsgroups: comp.std.c++
- Subject: Re: "explicit" default constructor?
- Date: 28 Mar 1996 20:27:21 GMT
- Organization: Technical University of Berlin
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <315AF30F.4855@cs.tu-berlin.de>
- References: <315A5C7A.6AF5@cs.tu-berlin.de> <4jeds0$h0b@engnews1.Eng.Sun.COM>
- NNTP-Posting-Host: taumet.eng.sun.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset="us-ascii"
- Content-Transfer-Encoding: 7bit
- X-Nntp-Posting-Host: 130.149.17.235
- X-Mailer: Mozilla 2.0 (Win95; I)
- X-Lines: 61
- Content-Length: 2294
- Originator: clamage@taumet
-
- Steve Clamage wrote:
- >
- > In article 6AF5@cs.tu-berlin.de, Roman Lechtchinsky <wolfro@cs.tu-berlin.de> writes:
- > >Steve Clamage wrote:
- > >
- > >> A converting constructor is one which can be called with a single parameter.
- > >> The default constructor isn't a converting constructor except in the
- > >> case of a constructor with all parameters having default values.
- > >>
- > >> If a constructor has no parameters, declaring it "explicit" has no effect,
- > >> since it can never be invoked for a conversion.
- > >
- > >> If a constructor's parameters all have default values, it can be a
- > >> converting constructor, and declaring it "explicit" prevents it from
- > >> being invoked implicitly.
- > >
- > >Yes, I've had this in mind, too. In the following case:
- > >
- > >class A
- > >{
- > > explicit A( int x=0 );
- > >};
- > >
- > >how do you call the default constructor?
- >
- > The same way you always did before. The default constructor is one which
- > requires no parameters. If implicitly or explicitly invoked with no
- > parameters, no conversion is taking place, and it is a non-converting
- > constructor.
-
- Sorry for posting another article on this topic ( I wasn't going to, honest )
- but I'm really not happy with this section of the DWP ( you might remember
- the thread about copy constructors ). However, you agree that a default
- constructor is a non-converting constructor. Then I read this passage in the
- DWP:
-
- A nonconverting constructor constructs objects just like converting
- constructors, but does so only where a constructor call is explicitly
- indicated by the syntax. [class.conv.ctor]
-
- Do you see how this can be interpreted? A default constructor is
- non-converting, so it constructs objects only if its call is "explicitly
- indicated". The DWP doesn't say that this section deals only with
- constructors that could be converting or are invoked for a conversion. BTW,
- I'm talking only about the definitions in the DWP, not about the language
- itself (i.e. I'm not confused how to call default constructors). So, if we
- argue strictly on the basis of the DWP, where am I wrong?
-
- >
- > > An explicit call would rather be
- > >
- > >A a();
- >
- > No, that declares 'a' to be a function with no parameters returning an
- > 'A' by value.
-
- Oops. Sure. Sorry. Probably I should get some sleep.
-
- Bye
-
- Roman
-
-
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-